home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / text / tex / tgrind.lha / TGrind / tgrind.sty < prev    next >
Text File  |  1993-01-04  |  3KB  |  89 lines

  1. % LaTeX tgrind environment
  2. %
  3. % $Header: tgrind.sty,v 1.3 88/08/14 17:43:54 van Exp $
  4. %
  5.  
  6. \newif\ifcomment\newif\ifstring
  7. \newbox\linesofar
  8. \newdimen\TBwid
  9. \newdimen\ts
  10. \newbox\tbox
  11.  
  12. \def\tgrind{\@ifnextchar[{\@tgrind}{\@tgrind[t]}}
  13. \def\@tgrind[#1]{%
  14. \ifhmode\par\fi
  15. \if #1n\newcount\linecount\newcount\linenext
  16. \def\L##1{\vbox{\hbox to\hsize{\CF\strut\global\advance\linecount by1
  17. ##1\hss\linebox}}}
  18. \linecount=0\linenext=9
  19. \def\linebox{\ifnum\linecount>\linenext\global\advance\linenext by10
  20. \hbox{\tiny\the\linecount}\fi}\else
  21. \def\L##1{\vbox{\hbox{\CF\strut ##1}}}\fi
  22. % Stuff we ignore.
  23. \let\Head=\@gobble
  24. \def\File##1,##2,##3{}
  25. \let\Proc=\@gobble
  26. \let\ProcCont=\@gobble
  27. %
  28. % Each formfeed in the input is replaced by a "\NewPage" macro.  If
  29. % you really want a page break here, define this as "\vfill\eject".
  30. \def\NewPage{\filbreak\bigskip}
  31. %
  32. \def\LB{\CF\hbox}
  33. \setbox\linesofar=\null
  34. \everyhbox={\box\linesofar}
  35. \def\Tab##1{\setbox\tbox=\lastbox\TBwid=1\wd\tbox\advance\TBwid by 1\ts
  36. \ifdim\TBwid>##1\ts
  37. \setbox\linesofar=\hbox{\box\tbox\Space}\else
  38. \setbox\linesofar=\hbox to ##1\ts{\box\tbox\hfil}\fi\LB}
  39. %
  40. % A normal space is too thin for code listings.  We make spaces & tabs
  41. % be in "\ts" units (which are the width of a "0" in the current font).
  42. \setbox\tbox=\hbox{0} \ts=1\wd\tbox \setbox\tbox=\hbox{\hskip 1\ts}
  43. \def\Space{\hskip 1\ts\relax}
  44. %
  45. % Font changing stuff for keywords, comments & strings.  We put keywords
  46. % in boldface, comments in text-italic & strings in typewriter.  Since
  47. % we're usually changing the font inside of a \LB macro, we remember the
  48. % current font in \CF & stick a \CF at the start of each new box.
  49. % Also, the characters " and ' behave differently in comments than in
  50. % code, and others behave differently in strings than in code.
  51. \let\CF=\rm
  52. \def\K##1{{\bf ##1}}    % Keyword
  53. \def\C{\it\global\let\CF=\it\global\commenttrue\relax}    % Comment Start
  54. \def\CE{\rm\global\let\CF=\rm\global\commentfalse\relax}% Comment End
  55. \def\S{\tt\global\let\CF=\tt\global\stringtrue\relax}    % String Start
  56. \def\SE{\rm\global\let\CF=\rm\global\stringfalse\relax}    % String End
  57. %
  58. % Special characters.
  59. \def\{{\ifmmode\lbrace\else\ifstring{\char'173}\else$\lbrace$\fi\fi}
  60. \def\}{\ifmmode\rbrace\else\ifstring{\char'175}\else$\rbrace$\fi\fi}
  61. \def\!{\ifmmode\backslash\else\ifstring{\char'134}\else$\backslash$\fi\fi}
  62. \def\|{\ifmmode|\else\ifstring{\char'174}\else$|$\fi\fi}
  63. \def\<{\ifmmode<\else\ifstring<\else$<$\fi\fi}
  64. \def\>{\ifmmode>\else\ifstring>\else$>$\fi\fi}
  65. \def\/{\ifmmode/\else\ifstring/\else$/$\fi\fi}
  66. \def\*{\ifmmode*\else\ifstring*\else$*$\fi\fi}
  67. \def\-{\ifmmode-\else\ifstring-\else$-$\fi\fi}
  68. \def\_{\ifstring{\char'137}\else\underline{\Space}\fi}
  69. \def\&{{\char'046}}
  70. \def\#{{\char'043}}
  71. \def\%{{\char'045}}
  72. \def\~{{\char'176}}
  73. \def\"{\ifcomment''\else{\tt\char'042}\fi}
  74. \def\'{\ifcomment'\else{\tt\char'047}\fi}
  75. \def\^{{\char'136}}
  76. \def\${{\rm\char'044}}
  77. \mathsurround 0pt
  78. \@tobeyspaces\if #1c\let\etgrind@=\etgrind@c\[\vbox\bgroup
  79. \else \if #1b\let\etgrind@=\etgrind@b \vbox\bgroup
  80. \else\let\etgrind@=\relax\fi\fi
  81. }
  82. \let\etgrind@=\relax
  83. \def\etgrind@c{\egroup\]}
  84. \def\etgrind@b{\egroup}
  85. \def\endtgrind{\etgrind@}
  86. {\catcode`\ =\active\gdef\@tobeyspaces{\catcode`\ \active\let \Space}}
  87.